<% if @ssh_public_key.new?
  action_type = "Register"
  action = "#{@project.path}/ssh-public-key"
else
  action_type = "Update"
  if @ssh_public_key.errors.empty?
    right_items = [part("components/delete_button", confirmation: @ssh_public_key.name, url: path(@ssh_public_key), redirect: "#{@project.path}/ssh-public-key")]
  end
end
@page_title = "#{action_type} SSH Public Key"
back = "#{@project.path}/ssh-public-key" %>

<%== part(
  "components/page_header",
  title: @page_title,
  back:,
  right_items:,
  breadcrumbs: [
    %w[Projects /project],
    [@project.name, @project.path],
    ["SSH Public Keys", back],
    %W[#{action_type} #]
  ]
) %>

<% form(action:, method: :post) do |f| %>
  <div class="grid gap-6">
    <div class="overflow-hidden rounded-lg shadow ring-1 ring-black ring-opacity-5 bg-white">
      <div class="px-4 py-5 sm:p-6">
        <div class="space-y-12">
          <div class="mt-2 grid grid-cols-1 gap-x-6 gap-y-8 sm:grid-cols-6">
            <div class="col-span-full">
              <%== part("components/form/text", name: "name", label: "Name", value: @ssh_public_key.name, attributes: {placeholder: "ssh-key-set-name", required: true}) %>
            </div>

            <div class="col-span-full">
              <%== part("components/form/textarea", name: "public_key", label: "Public Key", value: @ssh_public_key.public_key, attributes: {placeholder: "ssh-ed25519 ...\nssh-rsa ...", required: true}) %>
            </div>
          </div>
        </div>
      </div>
      <div class="px-4 py-5 sm:p-6">
        <div class="flex items-center justify-end gap-x-6">
          <a href="<%= @project.path %>/ssh-public-key" class="text-sm font-semibold leading-6 text-gray-900">Cancel</a>
          <%== part("components/form/submit_button", text: action_type) %>
        </div>
      </div>
    </div>
  </div>
<% end %>
